# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/30 22:46
from PyQt5.Qt import *


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QStackedWidget学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		self.list = QListWidget()
		self.list.insertItem(0, '联系方式')
		self.list.insertItem(1, '个人信息')
		self.list.insertItem(2, '教育程度')

		# 三个页面
		self.stack1 = QWidget()
		self.stack2 = QWidget()
		self.stack3 = QWidget()

		self.tab1UI()
		self.tab2UI()
		self.tab3UI()

		self.stack = QStackedWidget()
		self.stack.addWidget(self.stack1)
		self.stack.addWidget(self.stack2)
		self.stack.addWidget(self.stack3)

		hbox = QHBoxLayout()
		hbox.addWidget(self.list)
		hbox.addWidget(self.stack)
		self.setLayout(hbox)
		self.list.currentRowChanged.connect(self.display)

	def display(self, index):
		self.stack.setCurrentIndex(index)

	def tab1UI(self):
		# 表单布局
		layout = QFormLayout()
		layout.addRow('姓名', QLineEdit())
		layout.addRow('地址', QLineEdit())
		self.stack1.setLayout(layout)

	def tab2UI(self):
		# 水平布局
		layout = QFormLayout()
		sex = QHBoxLayout()
		sex.addWidget(QRadioButton('男'))
		sex.addWidget(QRadioButton('女'))
		layout.addRow(QLabel('性别'), sex)
		layout.addRow('生日', QLineEdit())
		self.stack2.setLayout(layout)

	def tab3UI(self):
		# 水平布局
		layout = QHBoxLayout()
		layout.addWidget(QLabel('科目'))
		layout.addWidget(QCheckBox('物理'))
		layout.addWidget(QCheckBox('高数'))
		self.stack3.setLayout(layout)


if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())
